package cn.tedu.xuecha.infrastructure;

import cn.tedu.xuecha.common.pojo.Content;
import cn.tedu.xuecha.dao.ContentDAO;
import cn.tedu.xuecha.domain.repository.ContentRepository;
import cn.tedu.xuecha.infrastructure.data.converter.ContentConverter;
import cn.tedu.xuecha.protocol.param.ContentDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author coinyang
 * @date 2023/5/4 15:47
 */
@Repository
public class ContentRepositoryImpl implements ContentRepository {
    @Autowired
    private ContentConverter contentConverter;

    @Autowired
    ContentDAO contentDAO;

    @Override
    public int insert(ContentDTO record) {
        Content content = contentConverter.toContent(record);
        return contentDAO.insert(content);
    }
    @Override
    public int insertSelective(Content record) {
        return 0;
    }

    @Override
    public Content selectByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public List<Content> list() {
        System.out.println("------------");
        return contentDAO.list();
    }

    public int updateByPrimaryKeySelective(ContentDTO record) {
        Content content = contentConverter.toContent(record);
        return contentDAO.updateByPrimaryKeySelective(content);
    }

    @Override
    public int updateByPrimaryKey(Content record) {
        return 0;
    }
}
